<template>
  <div>
    <el-form
      :model="dataForm"
      :rules="dataRule"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmit()"
      label-width="80px"
    >
      <el-form-item label="字典名称" prop="name">
        <el-input v-model="dataForm.name" placeholder="字典名称" />
      </el-form-item>
      <el-form-item label="字典类型" prop="type">
        <el-input v-model="dataForm.type" placeholder="字典类型" />
      </el-form-item>
      <el-form-item label="字典码" prop="code">
        <el-input v-model="dataForm.code" placeholder="字典码" />
      </el-form-item>
      <el-form-item label="字典值" prop="value">
        <el-input v-model="dataForm.value" placeholder="字典值" />
      </el-form-item>
      <el-form-item label="排序" prop="orderNum">
        <el-input v-model="dataForm.orderNum" placeholder="排序" />
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="dataForm.remark" placeholder="备注" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="$emit('close')">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    detailsData: Object
  },
  data() {
    return {
      visible: false,
      dataForm: {
        id: 0,
        name: "",
        type: "",
        code: "",
        value: "",
        orderNum: "",
        remark: "",
        delFlag: ""
      },
      dataRule: {
        name: [
          { required: true, message: "字典名称不能为空", trigger: "blur" }
        ],
        type: [
          { required: true, message: "字典类型不能为空", trigger: "blur" }
        ],
        code: [{ required: true, message: "字典码不能为空", trigger: "blur" }],
        value: [{ required: true, message: "字典值不能为空", trigger: "blur" }],
        orderNum: [{ required: true, message: "排序不能为空", trigger: "blur" }]
      }
    };
  },
  methods: {
    // 表单提交
    dataFormSubmit() {
      this.$refs["dataForm"].validate(valid => {
        if (valid) {
          this.$emit("close");
        }
      });
    }
  },
  watch: {
    detailsData: {
      handler(val) {
        this.dataForm = Object.assign({}, val);
        console.log(val, 7878);
      },
      immediate: true
    }
  }
};
</script>
